package com.longxi.tianjintianbao.ui.adapter.multitype;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.listener.SelectQualityItemListener;
import com.longxi.tianjintianbao.model.quality.QualityItem;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class QualityItemViewBinder extends ItemViewBinder<QualityItem, QualityItemViewBinder.ViewHolder> {

    SelectQualityItemListener listener;

    public QualityItemViewBinder(SelectQualityItemListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_quality_item, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull QualityItem qualityItem) {
        holder.mTvItemName.setText(qualityItem.getItemname());
//        holder.mTvItemstandard.setText(qualityItem.getItemstandard());
        if(!TextUtils.isEmpty(qualityItem.getScore())){
            holder.mTvScore.setText(qualityItem.getScore() + "分");
        }
        holder.mLlBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onSuccess(qualityItem);
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mLlBtn;
        TextView mTvItemName;
//        TextView mTvItemstandard;
        TextView mTvScore;
        ViewHolder(View itemView) {
            super(itemView);
            mLlBtn = itemView.findViewById(R.id.llBtn);
            mTvItemName = itemView.findViewById(R.id.tvItemName);
//            mTvItemstandard = itemView.findViewById(R.id.tvItemstandard);
            mTvScore = itemView.findViewById(R.id.tvScore);
    }
    }
}
